package com.krui.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpDownloader {
	URL url = null;

	public String download(String urlString) {
		StringBuffer sbBuffer = new StringBuffer();
		String line = null;
		BufferedReader bufferedReader = null;

		try {
			url = new URL(urlString);
			// 创建一个HTTP连接
			HttpURLConnection urlConn = (HttpURLConnection) url
					.openConnection();
			// 使用I/O读取数据(字节流-->字符流-->bufferReader)
			bufferedReader = new BufferedReader(new InputStreamReader(
					urlConn.getInputStream()));
			while ((line = bufferedReader.readLine()) != null) {
				sbBuffer.append(line);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			try {
				bufferedReader.close();
			} catch (Exception e2) {
				// TODO: handle exception
				e2.printStackTrace();
			}
		}
		return sbBuffer.toString();
	}
}
